Skip to content

feat(db): nullable MonthlyCost on PurchaseHistoryRecord (closes #255)#848

Open
cristim wants to merge 2 commits into
feat/multicloud-web-frontendfrom
fix/255-wave14
Open

feat(db): nullable MonthlyCost on PurchaseHistoryRecord (closes #255)#848
cristim wants to merge 2 commits into
feat/multicloud-web-frontendfrom
fix/255-wave14

Conversation

@cristim
Copy link
Copy Markdown
Member

@cristim cristim commented May 28, 2026

Summary

  • Makes PurchaseHistoryRecord.MonthlyCost a *float64 (nullable) so rows from providers that do not return a monthly recurring cost (e.g. Azure/GCP all-upfront) store NULL instead of a misleading 0.0.
  • Migration 000063 drops the NOT NULL constraint on purchase_history.monthly_cost; rollback coerces any NULLs back to 0.0 before re-adding the constraint.
  • Scans the column via sql.NullFloat64 in all three copies of the scan loop (production, comprehensive-test mock, additional-test mock) so NULL DB values materialise as a nil pointer and 0.0 DB values materialise as &0.0, preserving the semantic distinction.
  • Removes the derefFloat64 helper in execution.go that previously flattened nil to 0; now the pointer is passed through to the history record unchanged.
  • Frontend: monthly_cost typed as number | null; inventory commitment cell renders when null, $X.XX otherwise.
  • All consumers that aggregate MonthlyCost skip nil entries (no distortion of totals).

Test plan

  • go build ./... clean
  • go test github.com/LeanerCloud/CUDly/internal/config/... github.com/LeanerCloud/CUDly/internal/api/... 1906 pass
  • Migration 000063 up/down SQL reviewed: drops NOT NULL on purchase_history.monthly_cost; rollback NULLs-to-0 before re-adding constraint
  • Coverage breakdown handler skips nil MonthlyCost entries rather than adding zero

Closes #255

@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/few Limited audience effort/m Days type/feat New capability labels May 28, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

Warning

Review limit reached

@cristim, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 22 minutes and 59 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1881bbb4-236b-4596-8ab2-fd181c3a7b80

📥 Commits

Reviewing files that changed from the base of the PR and between 80c20d2 and 634ff44.

📒 Files selected for processing (21)
  • frontend/src/api/types.ts
  • frontend/src/inventory.ts
  • frontend/src/types.ts
  • internal/api/handler_history.go
  • internal/api/handler_history_test.go
  • internal/api/handler_inventory.go
  • internal/api/handler_inventory_test.go
  • internal/api/handler_per_account_perms_test.go
  • internal/api/types.go
  • internal/config/store_postgres.go
  • internal/config/store_postgres_additional_test.go
  • internal/config/store_postgres_comprehensive_test.go
  • internal/config/store_postgres_coverage_test.go
  • internal/config/store_postgres_db_test.go
  • internal/config/store_postgres_test.go
  • internal/config/store_postgres_unit_test.go
  • internal/config/types.go
  • internal/config/types_test.go
  • internal/database/postgres/migrations/000063_purchase_history_monthly_cost_nullable.down.sql
  • internal/database/postgres/migrations/000063_purchase_history_monthly_cost_nullable.up.sql
  • internal/purchase/execution.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/255-wave14

Comment @coderabbitai help to get the list of available commands and usage tips.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 28, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 28, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim
Copy link
Copy Markdown
Member Author

cristim commented May 30, 2026

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 30, 2026

✅ Actions performed

Full review triggered.

cristim added 2 commits June 1, 2026 19:25
Migration 000063 drops NOT NULL on purchase_history.monthly_cost so rows
from providers without a monthly recurring breakdown (Azure/GCP all-upfront)
can store NULL instead of a misleading 0.0.

- PurchaseHistoryRecord.MonthlyCost: float64 -> *float64
- InventoryCommitment.MonthlyCost: float64 -> *float64
- All scan loops use sql.NullFloat64; nil DB value -> nil pointer
- execution.go: remove derefFloat64; pass pointer straight through
- handler_inventory.go: skip nil MonthlyCost in coverage aggregation
- handler_history.go: sumRecommendationMonthlyCostPtr returns nil when
  every rec has nil MonthlyCost (renders as -- not $0.00)
- Frontend: monthly_cost typed number|null; inventory cell renders --
- All test fixtures and assertions updated to use *float64 (pf helper)
@cristim
Copy link
Copy Markdown
Member Author

cristim commented Jun 1, 2026

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/few Limited audience priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/feat New capability urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant